﻿//
// Created by Freeman on 2022/1/23.
//

#ifndef PAT_EXERCISES_UTIL_H
#define PAT_EXERCISES_UTIL_H

#include <string>
#include <vector>

class Util {
    constexpr static double eps = 1e-8;
public:
    static double round(double x, int k);

    static bool equal(double x, double y);

    /**
     * 判断浮点数x是否小于y。当x < y-(1E-8)时，认为x<y.
     *
     * @param x
     * @param y
     * @return
     */
    static bool less(double x, double y);

    /**
     * 判断浮点数x是否大于y。当x > y-(1E-8)时，认为x>y.
     *
     * @param x
     * @param y
     * @return
     */
    static bool more(double x, double y);

    /**
     * 判断浮点数x是否小于等于y。返回!more(x, y).
     *
     * @param x
     * @param y
     * @return
     */
    static bool lessEqual(double x, double y);

    /**
     * 判断浮点数x是否大于等于y。返回!less(x, y).
     *
     * @param x
     * @param y
     * @return
     */
    static bool moreEqual(double x, double y);

    static std::vector<std::string> strSplit(std::string str, char delimiter);

    /**
     * @brief 将十进制整数deci（≥0）转为任意进制base（≥2）的数。
     * @param deci
     * @param base
     * @return
    */
    static std::vector<int> deci2AnyBase(int deci, int base);

    static void quickSort(std::vector<int> &v, int start, int end);
};


#endif //PAT_EXERCISES_UTIL_H
